package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;
    @GetMapping("/all")
    public List<User> findAll(){
       return userService.findAll();
    }
    @PostMapping("/insertUser")
    public String insertUser(@RequestBody User user){
        userService.insertUser(user);
        return "用户添加成功!";
    }
    @DeleteMapping("/deleteUser/{id}")
    public String deleteUser(@PathVariable Integer id){
        userService.deleteUser(id);
        return "用户删除成功!";
    }
    @PutMapping("/updateUser")
    public String updateUser(@RequestBody User user){
        userService.updateUser(user);
        return "信息更改成功!";
    }
    @GetMapping("/selectUser")
    public List<User> selectUser(User user){
        System.out.println(user);
        return userService.selectUser(user);
    }
}
